package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理API", tags = "channel")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChanneController {

    @Autowired
    private AdChannelService adChannelService;

    @ApiOperation(value = "根据条件分页查询频道")
    @PostMapping("/list")
    public ResponseResult findChannelByPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findChannelByPage(channelDto);
    }

    @ApiOperation(value = "添加频道", tags = "频道名称不能为空，且频道名称不可以重复")
    @PostMapping("save")
    public ResponseResult addChannel(@RequestBody AdChannel adChannel) {
        return adChannelService.addChannel(adChannel);
    }

    @ApiOperation(value = "根据id修改频道")
    @PostMapping("update")
    public ResponseResult updateChannelById(@RequestBody AdChannel adChannel) throws Exception {
        return adChannelService.updateChannel(adChannel);
    }

    @ApiOperation(value = "根据id删除频道")
    @GetMapping("del/{id}")
    public ResponseResult deleteChannelById(@PathVariable("id") Integer id) {
        return adChannelService.deleteChannel(id);
    }

    @ApiOperation(value = "查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findChannelList() {
        return adChannelService.findAllChannels();
    }
}
